package com.lsa.google.trials;

public class SkippedProductCalculator
{
    public static int[] calculateOn(int[] array)
    {
        int[] result_array = new int[array.length];
        
        int k = 0; // current item
        
        for( int i = 0; i < array.length; i++ )
        {
            int product = 1;
            
            for( int j = 0; j < array.length; j++ )
            {
                if (j != k)
                {
                    product *= array[j];
                }
            }
            
            result_array[k] =  product;
            k++;
        }
        
        return result_array;
    }
    
    public static int[] calculateOn2(int[] array)
    {
        int[] result_array = new int[array.length];
        
        int k = 0; // current item
        
        for( int i = 0; i < array.length; i++ )
        {
            int product = 1;
            
            for( int j = 0; j < array.length; j++ )
            {
                if (j != k)
                {
                    product *= array[j];
                }
            }
            
            result_array[k] =  product;
            k++;
        }
        
        return result_array;
    }
    
    /**
     * Silly method with division for verification 
     */
    public static int[] calculateForVerification(int[] array)
    {
        int[] result_array = new int[array.length];
        
        int product = 1;
        
        for( int i = 0; i < array.length; i++ )
        {
            product =  product * array[i];
        }
        
        for( int i = 0; i < array.length; i++ )
        {
            result_array[i] =  product / array[i];
        }
        
        return result_array;
    }
}
